package Controller

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"time"
	"web_back_go/DAO/gorm"
	"web_back_go/DAO/gorm/GormModel"
	"web_back_go/Dto"
	"web_back_go/Response"
)

/*
GetCategoryInfo

	@Operation(summary = "分类信息列表" , description = "获取所有的产品分类信息，顶级分类的parentId为0,默认为顶级分类")
*/
func GetCategoryInfo(c *gin.Context) {
	parentIdStr := c.Query("parentId")
	var parentId int
	if parentIdStr == "" {
		parentId = 0
	} else {
		parentId, _ = strconv.Atoi(parentIdStr)
	}

	db := gorm.Db
	//select category_id,category_name,`seq`,`status`,pic from tz_category where parent_id = #{parentId} and `status` = 1 order by seq
	var categoryList []Dto.CategoryDto
	db.Model(&GormModel.TzCategory{}).Where("parent_id = ? and `status` = 1", parentId).Order("seq").Find(&categoryList)

	c.JSON(200, Response.ResponseBody{
		Code:      "00000",
		Msg:       nil,
		Data:      categoryList,
		Version:   "V1.0.0",
		Timestamp: time.Now().Unix(),
		Sign:      nil,
		Success:   true,
	})

}
